﻿@inherits BaseComponent

@if (!string.IsNullOrWhiteSpace(AuthId))
{
    if (Context.HasButton(AuthId))
    {
        @RenderButtonComponent()
    }
}
else
{
    @RenderButtonComponent()
}

@code {
    private RenderFragment RenderButton => @<Button Class="@Class" Icon="@Icon" Type="@Type" Style="@Style"
                                                    Block="Block" Danger="Danger" Disabled="!Enabled" Loading="isLoad"
                                                    OnClick="OnButtonClickAsync">@Language[Name]</Button>;

    private RenderFragment RenderButtonComponent()
    {
        if (!string.IsNullOrWhiteSpace(Title))
            return @<Tooltip TitleTemplate="TitleTemplate(Title)">@RenderBadgeButton()</Tooltip>;
        else
            return RenderBadgeButton();
    }

    private RenderFragment RenderBadgeButton()
    {
        if (Badge <= 0)
            return RenderButton;

        return @<Badge Count="Badge">@RenderButton</Badge>;
    }
}